$(document).ready(function(event){	
	$('.adminMain').split({
	    orientation: 'vertical',
	    limit: 150,
	    position: '15%' // if there is no percentage it interpret it as pixels
	});
	
//################ Begin Settings ################
	//GUX Options
	var rootSelector = ".adminMain > ";
	var treeColourClass = "treeview-gray";
	//var menu = $(".header-menu .menu ul").children(".menu-on");
	//var sysCode = $(menu).children("span").eq(1).text();
	var sysCode = $("#adminTreeviewRootId").text();
	
	//jQuery Treeview Options
	var treeviewId = sysCode;
	var navi = true; //< false | true >
	var animated = false;//< false | "slow" | "fast" >
	var collapsed = true; //< false | true >
	var persist = false; //< false | "cookie" >
	var cookieId = false; //< false | "treeview-gray" >
	
	//Data Options
	var jqOpts = new jqTreeTypeOption();
	var type = jqOpts.callType[0];//< "D" | "P" | "J" >
	var callback = jqOpts.returnBack[5];//< "htmlFile" | "jsonFile" | "htmlManual" | "jsonManual" | "htmlDb" | "jsonDb" >
	var treeDataFile = "datas/system/system";
//################ End Settings ##################

	var options = new Object();	
	options["controller"] = rootSelector + ".treeviewContainer > .treeviewController";
	options["content"] = rootSelector + ".treeviewContainer > .treeviewContent";
	options["canvas"] = rootSelector + ".treeviewCanvas > .dom";
	options["rootTreeId"] = treeviewId;
	options["treeColourClass"] = treeColourClass;
	options["navi"] = navi;
	options["animated"] = animated;
	options["collapsed"] = (type == jqOpts.callType[1])?false:collapsed;
	options["persist"] = persist;
	options["cookieId"] = cookieId;
	options["jsonRootKey"] = treeviewId;
	options["treeDataFile"] = treeDataFile;
	options["type"] = type;
	options["callback"] = callback;
	//options["clickingSelected"] = false;
		
	var jqTree = new jqTreeview(options);
	runTreeview(jqTree, jqOpts);
});

function runTreeview(jqTree, jqOpts){
	if(jqTree.jqTreeOpts.type == jqOpts.callType[0]){//Dwr -> DirectWebRemoting
		$(jqTree.jqTreeOpts.content).html("");
		treeviewSysMenu.treeMenuList(jqTree.jqTreeOpts, dwrViewHandler(jqTree, jqOpts));
		
	}else if(jqTree.jqTreeOpts.type == jqOpts.callType[1]){//prefixed Elements. 
		jqTree.treeMenuSet(); 
		
	}else{	//if(jqTree.jqTreeOpts.type == jqOpts.callType[2]){//JSON 
		var content = $(jqTree.jqTreeOpts.content);
		var data = $(content).text();
		$(content).html("");
		
		var jHelper = new jsonHelper2();
		var obj = jHelper.stringToJsonObj(data);
		$(jqTree.jqTreeOpts.content).append(jqTree.listInit(obj));
		jqTree.treeMenuSet();
	}
}

//###.Begin Functionalities for Dwr -> DirectWebRemoting
function dwrViewHandler(jqTree, jqOpts){
	return (jqTree.compareArray(jqOpts.returnJson, jqTree.jqTreeOpts.callback)) 
	? function jsonView(data){
		var jHelper = new jsonHelper2();
		var obj = jHelper.stringToJsonObj(data);
		$(jqTree.jqTreeOpts.content).append(jqTree.listInit(obj)); 
		jqTree.treeMenuSet(); }
	
	: function htmlView(data){
		$(jqTree.jqTreeOpts.content).html(data); 
		jqTree.treeMenuSet(); }
	;
}
//###.End Functionalities for Dwr -> DirectWebRemoting
